package com.ali.aliwebsite.controller;

import com.ali.aliwebsite.entity.News;
import com.ali.aliwebsite.entity.Video;
import com.ali.aliwebsite.mapper.NewsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class NewsController {
    @Autowired
    NewsMapper newsMapper;

    @RequestMapping("/news/list")
    public List<News> selectAll() {
        List<News> newsList = newsMapper.selectAll();
        return newsList;
    }

    @RequestMapping("admin/news/list")
    public List<News> selectAdminAll() {
        List<News> newsList = newsMapper.selectAll();
        return newsList;
    }

    //根据ID更新title
    @RequestMapping("admin/news/updateTitle")
    public String updateTitle(@RequestParam String title, @RequestParam int id) {
        newsMapper.updateTitle(title, id);
        return "success";
    }

    //根据ID更新图片URL
    @RequestMapping("admin/news/updateImage")
    public String updateImage(@RequestParam String image, @RequestParam int id) {
        newsMapper.updateImage(image, id);
        return "success";
    }
}
